<template>
	<view class="sh-grid-box mb10">
		<view class="tool-item y-f" v-for="(menu, index) in detail.list" :key="index" @tap="jump(menu)">
			<image class="tool-img" :src="menu.image" mode="aspectFill"></image>
			<text class="item-title">{{ menu.name }}</text>
		</view>
		<view class="tool-item y-f" @tap="jump({path: '/pages/user/myFriends'})">
			<image class="tool-img" src="https://shopro-1253949872.file.myqcloud.com/uploads/20200704/5d53a6e7f940c5ef925f63c1810c8429.png" mode="aspectFill"></image>
			<text class="item-title">我的好友</text>
		</view>
		<!-- <view class="tool-item y-f" @tap="scanCode"> -->
		<view class="tool-item y-f" v-if="userInfo.group_id == 2" @tap="scanCode">
			<image class="tool-img" src="https://sprtcar.oss-cn-chengdu.aliyuncs.com/home/20210708094906.png" mode="aspectFill"></image>
			<text class="item-title">扫码</text>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	/**
	 * 自定义之宫格列表
	 * @property {Object} detail  - 宫格信息
	 */
	export default {
		components: {},
		data() {
			return {
				routerTo: this.$tools.routerTo
			};
		},
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo
			}),
		},
		props: {
			detail: {
				type: Object,
				default: null
			}
		},
		methods: {
			jump(data) {
				console.log(data)
				this.$tools.routerTo(data.path);
			},
			scanCode() {
				let that = this
				uni.scanCode({
				    success: function (res) {
							let path = res.path
							let id = path.split('?')[1].split("=")[1]
							that.verification(id)
							console.log('条码类型：' + res);
							console.log(id);
							console.log('条码内容：' + res.path);
				    }
				})
			},
			// 核销
			verification(id) {
				let that = this
				that.$apiBase('verification', {
					id
				}).then(res => {
					if (res.code === 1) {
						uni.showToast({
							title: '核销成功'
						})
					}
				})
			}
		}
	};
</script>

<style lang="scss">
	// 宫格
	.sh-grid-box {
		background: #fff;
		display: flex;
		flex-wrap: wrap;
		padding-bottom: 40rpx;

		.tool-item {
			width: (750rpx/4);
			padding-top: 40rpx;

			.tool-img {
				width: 44rpx;
				height: 44rpx;
				// background: #ccc;
			}

			.item-title {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: rgba(153, 153, 153, 1);
				line-height: 24rpx;
				padding-top: 30rpx;
			}
		}
	}
</style>
